package LC;

/**
 * https://leetcode.com/problems/excel-sheet-column-title/description/
 * Given a positive integer, return its corresponding column title as appear in an Excel sheet.
 * For example:
 * 1 -> A
 * 2 -> B
 * 3 -> C
 * ...
 * 26 -> Z
 * 27 -> AA
 * 28 -> AB
 */
public class LC_168_ExcelSheetColumnTitle_Radix_Loop {
    public static void main(String[] args) {
        System.out.println(Solution.convertToTitle(100));
    }

    static class Solution {
        static String convertToTitle(int n) {
            char[] result = new char[20];
            int index = 20;
            n--;
            do {
                result[--index] = (char) ('A' + n % 26);
                n = n / 26 - 1;
            } while (n >= 0);
            return new String(result, index, 20 - index);
        }
    }
}